package edu.nf.postlikework.controller.app;

import edu.nf.postlikework.controller.BaseController;
import edu.nf.postlikework.model.dto.PostDTO;
import edu.nf.postlikework.model.entity.User;
import edu.nf.postlikework.result.ResultVo;
import edu.nf.postlikework.service.PostService;
import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *
 * @author zjl
 * @date 2025/10/13
 */
@RestController
@RequiredArgsConstructor
public class PostController extends BaseController {
    private final PostService postService;

    @GetMapping("/post/list")
    public ResultVo<List<PostDTO>> getAllPostsByUserId(int pageNum, int pageSize, HttpSession session){
        User user = (User) session.getAttribute("user");
        Integer userId = user!=null ?user.getUserId():-1;
        List<PostDTO> list = postService.postList(pageNum, pageSize, userId);
        return success(list);
    }
}
